home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Support / BCPool.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  1.6 KB  |  78 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  BCPool.h
  5. //
  6. //  This file contains the declaration of the heap storage management class.
  7.  
  8. #ifndef BCPOOL_H
  9. #define BCPOOL_H 1
  10.  
  11. #include <stddef.h>
  12. #include "BCType.h"
  13.  
  14. // Class denoting a pool of memory stored on the heap
  15.  
  16. class BC_CPool {
  17. public:
  18.  
  19.   BC_CPool(size_t chunkSize);
  20.   ~BC_CPool();
  21.   
  22.   void* Allocate(size_t);
  23.   void Deallocate(void*, size_t);
  24.   
  25.   void Preallocate(BC_Index numberOfChunks);
  26.   void ReclaimUnusedChunks();
  27.   void PurgeUnusedChunks();
  28.   
  29.   size_t ChunkSize() const 
  30.     {return fChunkSize;}
  31.   BC_Index TotalChunks() const
  32.     {return (NumberOfDirtyChunks() + NumberOfUnusedChunks());}
  33.   BC_Index NumberOfDirtyChunks() const;
  34.   BC_Index NumberOfUnusedChunks() const;
  35.   
  36. protected:
  37.  
  38.   struct BC_SElement {
  39.     BC_SElement* fNextElement;
  40.     BC_SElement() : fNextElement(0) {}
  41.   };
  42.     
  43.   struct BC_SChunk {
  44.     BC_SChunk* fPreviousSizedChunk;
  45.     BC_SChunk* fNextSizedChunk;
  46.     BC_SChunk* fNextChunk;
  47.     BC_Index fElementSize;
  48.     BC_Index fNumberOfElements;
  49.     BC_SElement* fNextElement;
  50.     BC_SChunk()
  51.       : fPreviousSizedChunk(0),
  52.         fNextSizedChunk(0),
  53.         fNextChunk(0),
  54.         fElementSize(0),
  55.         fNumberOfElements(0),
  56.         fNextElement(0) {}
  57.   };
  58.  
  59.   BC_SChunk* fHead;
  60.   BC_SChunk* fUnusedChunks;
  61.   size_t fChunkSize;
  62.   size_t fUsableChunkSize;
  63.  
  64.   BC_SChunk* GetChunk(size_t s);
  65.   
  66.   static size_t Align(size_t);
  67.   
  68. private:
  69.  
  70.   BC_CPool(const BC_CPool&) {}
  71.   void operator=(const BC_CPool&) {}
  72.   void operator==(const BC_CPool&) {}
  73.   void operator!=(const BC_CPool&) {}
  74.   
  75. };
  76.  
  77. #endif
  78.